package com.nexttwist.common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class BasicValidator {

	private String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
	
	/**
	 * This method is to check Null or Empty
	 * 
	 * @param value
	 * @return boolean
	 */
	public boolean isEmptyOrNull(String value) {
		if (value == null || value.trim().isEmpty()) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * To check integer or not
	 * 
	 * @param input
	 * @return
	 */
	public boolean isInteger(String input) {
		try {
			Long.parseLong(input);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	/**
	 * To validate the Email 
	 * 
	 * @param email
	 * @return
	 */
	public boolean isValidEmail(String email) {
		Pattern pattern = Pattern.compile(EMAIL_PATTERN);
		Matcher matcher = pattern.matcher(email);
		return matcher.matches();
	}
	
	
	/**
	 * To check the Object for Null
	 * 
	 * @param object
	 * @return true/false
	 */
	
	public boolean isNullOrBlank(Object object) {
		if (object == null)
			return true;
		else if (object.getClass() == String.class)
			if (String.valueOf(object).trim().length() == 0)
				return true;
			else
				return false;
		else
			return false;
	}

}